package org.clockworkmages.games.anno1186.situations.inventory;

import java.util.List;

import org.clockworkmages.games.anno1186.GameBeansContext;
import org.clockworkmages.games.anno1186.generator.sets.TechnicalSituationConstants;
import org.clockworkmages.games.anno1186.model.item.Item;
import org.clockworkmages.games.anno1186.model.option.GoBackOption;
import org.clockworkmages.games.anno1186.model.option.Option;
import org.clockworkmages.games.anno1186.model.situation.Situation;
import org.clockworkmages.games.anno1186.scripting.PlayerCharacterScriptingWrapper;

public class InventoryItemSituation
		extends Situation {

	private Item item;

	public InventoryItemSituation(final Item item) {
		this.item = item;
		this.setTitle(item.getName());
		this.setText(item.getDescription());

		List<Option> options = getOptions();

		Option option;

		if (item.getEquipmentSlotId() != null) {
			option = new Option() {
				@Override
				public void select() {
					PlayerCharacterScriptingWrapper playerCharacterScriptingWrapper = GameBeansContext
							.getBean(PlayerCharacterScriptingWrapper.class);
					playerCharacterScriptingWrapper.equipItem(item.getId());
					super.select();
				}
			};
			option.setLabel("Equip");
			option.setGoToSituation(TechnicalSituationConstants.ST_EMPTY_RETURN);
			options.add(option);
		}

		options.addAll(item.getUseOptions());

		option = new Option() {
			@Override
			public void select() {
				PlayerCharacterScriptingWrapper playerCharacterScriptingWrapper = GameBeansContext
						.getBean(PlayerCharacterScriptingWrapper.class);
				playerCharacterScriptingWrapper.removeItem(item.getId());
				super.select();
			}
		};
		option.setLabel("Discard");
		option.setGoToSituation(TechnicalSituationConstants.ST_EMPTY_RETURN);
		options.add(option);

		options.add(GoBackOption.INSTANCE);
	}

	public Item getItem() {
		return item;
	}
}
